package cn.acac.yygh.hosp.controller.user;

import cn.acac.yygh.hosp.service.ScheduleService;
import cn.acac.yygh.model.hosp.Schedule;
import cn.acac.yygh.result.R;
import cn.acac.yygh.vo.hosp.ScheduleOrderVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user/hosp/schedule")
@Api("排班的控制层")
public class UserScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    /**
     * 获取该医院该科室下的排班信息
     * @param hospcode
     * @param deptcode
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/{hospcode}/{deptcode}/{pageNum}/{pageSize}")
    public R selectBookingSchedule(@PathVariable String hospcode,
                                   @PathVariable String deptcode,
                                   @PathVariable Integer pageNum,
                                   @PathVariable Integer pageSize){
        Map<String,Object> scheduleMap = scheduleService.selectBookingSchedule(hospcode,deptcode,pageNum,pageSize);
        return R.ok().setData(scheduleMap);
    }

    /**
     * 查询当天的值班医生
     * @param hospcode
     * @param deptcode
     * @param wordDate
     * @return
     */
    @GetMapping("/{hospcode}/{deptcode}/{wordDate}")
    public R selectScheduleDetail(@PathVariable String hospcode,
                                  @PathVariable String deptcode,
                                  @PathVariable String wordDate){
        List<Schedule> details = scheduleService.dateil(hospcode, deptcode, wordDate);
        return R.ok().setData("details",details);
    }

    /**
     * 根据排班id查询排班医生信息
     * @param id
     * @return
     */
    @GetMapping("/findScheduleById/{id}")
    public R findScheduleById(@PathVariable String id){
        Schedule schedule = scheduleService.findScheduleById(id);
        return R.ok().setData("schedule",schedule);
    }

    /**
     * 别的服务远程调用的接口
     * @param scheduleId
     * @return
     */
    @GetMapping("/findSchedule/{scheduleId}")
    public ScheduleOrderVo findScheduleOrderById(@PathVariable("scheduleId") String scheduleId){
        ScheduleOrderVo scheduleOrderVo = scheduleService.findScheduleOrderById(scheduleId);
        return scheduleOrderVo;
    }
}
